(function(Game){
    function Pipe(option){
        this.ctx=option.ctx;
        this.upImg=option.upImg;
        this.downImg=option.downImg;
        this.width=this.upImg.width;
        this.spaceX=200;
        this.spaceY=150;
        this.index=option.index||0;
        this.x=200+this.index*this.spaceX;
        this.y=0;

        this.setPos();

    }

    Pipe.prototype.render=function(){
        this.x-=5;
        if(this.x<-200){
            this.x=this.spaceX*5;
        }
        var startY=this.upImg.height-this.y;

        this.ctx.drawImage(this.upImg,0,startY,this.width,this.y,this.x,0,this.width,this.y);

        var dy=this.y+this.spaceY;
        var dh=this.ctx.canvas.height-this.y-this.spaceY;
        this.ctx.drawImage(this.downImg,0,0,this.width,dh,this.x,dy,this.width,dh);           
        this.ctx.rect(this.x,0,this.width,this.y);
        this.ctx.rect(this.x,dy,this.width,dh);
        this.ctx.stroke();

    }

    Pipe.prototype.setPos=function(){
        this.y=100+parseInt(Math.random()*100);
    }

    Pipe.prototype.impact=function(x,y){
        if(ctx.isPointInPath(x,y)){
           alert(1);
        }
    }

    Game.Pipe=Pipe;
})(Game);
